﻿using movie.tool.module.film.service;
using System;
using System.Windows;
using System.Windows.Threading;

namespace movie_tool
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// 测试版本标记,为true表示测试版本,连接测试服务器.false为正式版本,连接华为云服务器
        /// </summary>
        public static bool APP_FOR_TEST = false;
        private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            try
            {
                MovieService.Instance.LoadLocalMovies();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "加载本地剧本失败");
                MessageBox.Show("加载本地剧本失败");
            }
        }

        private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            logger.Error(e.Exception,"未处理异常");
            if(e.Exception != null)
            {
                Dispatcher d = e.Dispatcher != null ? e.Dispatcher : App.Current.Dispatcher;
                d.Invoke(() => {
                    MessageBox.Show(e.Exception.Message);
                });
            }
            e.Handled = true;
        }
    }
}
